package util;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.Map;

import dataModel.Product;
import dataModel.Review;

public class write2File {
	public static void write(Map<String, Product> items, String filename) {
		try {
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(filename)));
			for (String key : items.keySet())
				bw.write(items.get(key).toString() + "\n\r");
			bw.flush();
			bw.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
		}
	}

	public static void writeReview(List<Review> reviews, String filename) {
		try {
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(filename)));
			if (reviews != null) {
				for (Review review : reviews)
					bw.write(review.getGoodQuality() + "; "
							+ review.getBadQuality() + "; "
							+ review.getSummary() + "\n\r");
			}
			bw.flush();
			bw.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
		}
	}
}
